package br.com.moove.bananasfit.control;

import java.util.List;

import com.android.volley.toolbox.NetworkImageView;

import br.com.moove.bananasfit.model.PessoaJuridica;
import br.com.moove.bananasfit.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class PessoaJuridicaAdapter extends ArrayAdapter<PessoaJuridica> {

	static final int LAYOUT = R.layout.activity_pjuridica_item_lista;

	public PessoaJuridicaAdapter(Context context, List<PessoaJuridica> objects) {

		super(context, LAYOUT, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		Context ctx = parent.getContext();
		if (convertView == null) {
			convertView = LayoutInflater.from(ctx).inflate(LAYOUT, null);
		}
		NetworkImageView img = (NetworkImageView) convertView
				.findViewById(R.id.imageViewPJuridica);
		TextView txtPJNome = (TextView) convertView
				.findViewById(R.id.textViewPJuridicaNome);

		RatingBar ratingBarListaPJ = (RatingBar) convertView
				.findViewById(R.id.ratingBarListaPJ);

		PessoaJuridica pessoaJuridica = getItem(position);
		txtPJNome.setText(pessoaJuridica.getNome());
		ratingBarListaPJ.setRating(pessoaJuridica.getMedia());
		img.setImageUrl(pessoaJuridica.getImgUrl(), VolleySingleton
				.getInstance(getContext()).getImageLoader());

		return convertView;
	}

}
